﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;

public partial class CustomControls_SiteNavigation : UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            var dataSource = Entities.GetCategories(0);
            if (dataSource != null)
            {
                dlStructure.DataSource = dataSource;
                dlStructure.DataBind();
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }

    protected void dlSubCategories_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            try
            {
                var subsubCategories = (Repeater)e.Item.FindControl("subsubCategories");
                var dataSource = Entities.GetCategories(((Categories)e.Item.DataItem).CategoryID);
                if (dataSource.Length > 0)
                {
                    subsubCategories.Visible = true;
                    subsubCategories.DataSource = dataSource;
                    subsubCategories.DataBind();
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }
    }
}